package Exp2_ChenGY;

import java.time.LocalDate;  
import java.time.Month;  
  
// 抽象基类 Employee  
abstract class Employee {  
    private String id;  
    private String name;  
    private LocalDate birthDate;  
  
    public Employee(String id, String name, LocalDate birthDate) {  
        this.id = id;  
        this.name = name;  
        this.birthDate = birthDate;  
    }  
  
    // Getter 方法  
    public String getId() {  
        return id;  
    }  
  
    public String getName() {  
        return name;  
    }  
  
    public LocalDate getBirthDate() {  
        return birthDate;  
    }  
  
    // 抽象方法，子类需要实现  
    public abstract double calculateSalary();  
  
    // 显示员工信息  
    public void displayInfo(Month currentMonth) {  
        double salary = calculateSalary();  
        if (birthDate.getMonth().equals(currentMonth)) {  
            salary += 100; // 生日月份加100元红包  
        }  
        System.out.println("工号: " + id + ", 姓名: " + name + ", 出生年月: " + birthDate.getMonthValue() + "-" + birthDate.getDayOfMonth()  
                + ", 月收入: " + salary);  
    }  
}  
  
// 领固定月薪的员工  
class SalariedEmployee extends Employee {  
    private double monthlySalary;  
  
    public SalariedEmployee(String id, String name, LocalDate birthDate, double monthlySalary) {  
        super(id, name, birthDate);  
        this.monthlySalary = monthlySalary;  
    }  
  
    @Override  
    public double calculateSalary() {  
        return monthlySalary;  
    }  
}  
  
// 计时取酬的员工  
class HourlyEmployee extends Employee {  
    private double hourlyRate;  
    private int hoursWorked;  
  
    public HourlyEmployee(String id, String name, LocalDate birthDate, double hourlyRate, int hoursWorked) {  
        super(id, name, birthDate);  
        this.hourlyRate = hourlyRate;  
        this.hoursWorked = hoursWorked;  
    }  
  
    @Override  
    public double calculateSalary() {  
        double baseSalary = hourlyRate * hoursWorked;  
        if (hoursWorked > 160) {  
            baseSalary += (hoursWorked - 160) * hourlyRate * 1.5; // 加班费  
        }  
        return baseSalary;  
    }  
}  
  
// 按销售额提成的员工  
class CommissionEmployee extends Employee {  
    private double grossSales;  
    private double commissionRate;  
  
    public CommissionEmployee(String id, String name, LocalDate birthDate, double grossSales, double commissionRate) {  
        super(id, name, birthDate);  
        this.grossSales = grossSales;  
        this.commissionRate = commissionRate;  
    }  
  
    @Override  
    public double calculateSalary() {  
        return grossSales * commissionRate;  
    }  
}  
  
// 带底薪并按销售额提成的员工  
class BasePlusCommissionEmployee extends CommissionEmployee {  
    private double baseSalary;  
  
    public BasePlusCommissionEmployee(String id, String name, LocalDate birthDate, double grossSales, double commissionRate, double baseSalary) {  
        super(id, name, birthDate, grossSales, commissionRate);  
        this.baseSalary = baseSalary;  
    }  
  
    @Override  
    public double calculateSalary() {  
        return super.calculateSalary() + baseSalary;  
    }  
}  
  
// 主类，用于测试  
public class SalaryPay {  
    public static void main(String[] args) {  
        // 假设当前月份为1月  
        Month currentMonth = Month.JANUARY;  
  
        // 创建Employee数组  
        Employee[] employees = {  
            new SalariedEmployee("001", "张三", LocalDate.of(1990, 1, 15), 5000),  
            new HourlyEmployee("002", "李四", LocalDate.of(1992, 3, 10), 20, 200),  
            new CommissionEmployee("003", "王五", LocalDate.of(1991, 1, 5), 10000, 0.05),  
            new BasePlusCommissionEmployee("004", "赵六", LocalDate.of(1993, 2, 1), 15000, 0.08, 3000)  
        };  
  
        // 遍历数组并显示每个员工的工资信息  
        for (Employee employee : employees) {  
            employee.displayInfo(currentMonth);  
        }  
    }  
}